package cn.getech.data.development.mapper;


import cn.getech.data.development.entity.ConfConnect;
import cn.getech.data.development.entity.TableInfo;
import cn.getech.data.development.entity.TableRelationshipEntity;
import cn.getech.data.development.model.dto.CollectionTaskUpdateDbDto;
import cn.getech.data.development.model.dto.ConfConnectDto;
import cn.getech.data.development.model.dto.ProcDatasDto;
import cn.getech.data.development.model.qo.ConfConnectQO;
import cn.getech.data.development.model.req.confconnect.TableInfoFieldRelationReq;
import cn.getech.data.development.model.req.confconnect.TableInfoFieldReq;
import cn.getech.data.development.model.res.confconnect.TableField;
import cn.getech.data.development.model.res.confconnect.TableInfoFieldRes;
import cn.getech.data.development.model.res.dataService.CollectTaskRes;
import cn.getech.data.development.model.res.dataService.DataServiceRes;
import cn.getech.data.development.model.vo.UserCreaterVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 配置连接表 Mapper 接口
 * </p>
 *
 * @author zenith
 * @since 2018-08-22
 */
@Mapper
public interface ConfConnectMapper extends BaseMapper<ConfConnect> {
    Integer listAllSourceCount(Map<String,Object> params);
    List<ConfConnect> listAllSource(Map<String,Object> params);

    IPage<ConfConnect> selectListPage(Page<ConfConnect> page, @Param("params") Map<String, Object> params);
    IPage<ConfConnect> listNoRelation(Page<ConfConnect> page, @Param("params") Map<String, Object> params);

    IPage<ConfConnect> listNoRelationByTenant(Page<ConfConnect> page, @Param("params") Map<String, Object> params);

    /**
    * @Description   根据typeId和工程id查询到对应的数据源集合
    * @Author  hujz
    * @Date   2019/8/24 15:17
    * @Param
    * @Return
    * @Exception
    *
    */
    List<ConfConnect> selectListByTypeIdAndProceId(ConfConnectQO confConnectQO);


    /***
     * 查询所有已启用的的连接任务
     * @Author  hujz
     * @return
     */
    List<ConfConnectDto> selectAllanalysisInfoDataStatusUp();


    /***
     * 查询所有已启用的的连接任务
     * @Author  hujz
     * @return
     */
    ConfConnectDto selectAllanalysisInfoDataStatusUpStop(@Param("analysisId") String analysisId);

    /***
     * 根据项目以及名称模糊查询数据源
     * @Author  wcj
     * @return
     */
    List<ConfConnect> selectByNameAndProId(@Param("params") Map<String, Object> params);
    IPage<ConfConnect> pageByNameAndProId(Page<ConfConnect> page, @Param("params") Map<String, Object> params);

    List<ConfConnect> selectByIds(@Param("connectIds") Set<Integer> connectIds);

    void insertAndId(@Param("confConnect") ConfConnect confConnect);

    List<ConfConnect> listNewNoRelation(@Param("params") Map<String, Object> params);

    List<ConfConnect> getDataSource(@Param("params") Map<String, Object> params);


    int updateCollectionTaskDbName(CollectionTaskUpdateDbDto collectionTaskUpdateDbDto);

    List<UserCreaterVO>  selectCreaterList();

    List<String> getMetaDbNames(@Param("sourceId") Integer id, @Param("sourceConf") String sourceConf, @Param("tenantId")Integer tenantId);

    List<TableInfoFieldRes> getMetaTables(@Param("params") TableInfoFieldReq req);

    List<TableRelationshipEntity> getMetaTableFields(@Param("tableIds") List<Integer> tableIds,@Param("currentTableId")  Integer currentTableId);

    TableInfo selectTableByName(@Param("params") TableInfoFieldRelationReq req);

    List<TableField> selectListByTableId(@Param("id")Integer id);

    List<TableInfoFieldRes> getMetaTablesByConfig(@Param("sourceConf") String sourceConf,
                                                  @Param("sourceId") Integer sourceId, @Param("tenantId")Integer tenantId);

    List<ProcDatasDto> listProcConnects();

    @MapKey(value = "id")
    List<Map<Long,String>> selectDataSourceType(@Param("params") Map<String, Object> params);

    @MapKey(value = "id")
    List<Map<String,Object>> selectDataSourceProc(@Param("params") Map<String, Object> params);

    List<Integer> permissionDateIds(@Param("userId")Integer userId,@Param("dataType")Integer dataType);

    IPage<DataServiceRes> searchDataServicePage(Page page,@Param("params") Map<String, Object> params);

    @MapKey(value = "id")
    List<Map<Long,String>> searchDataServiceGroup(@Param("params") Map<String, Object> params);

    @MapKey(value = "id")
    List<Map<Integer,String>> searchDataServiceSource(@Param("params") Map<String, Object> params);

    IPage<CollectTaskRes> searchCollectTaskPage(Page page,@Param("params") Map<String, Object> params);

    @MapKey(value = "id")
    List<Map<Integer,String>> searchCollectTaskSource(@Param("params") Map<String, Object> params);

    @MapKey(value = "id")
    List<Map<Integer,String>> searchCollectTaskType(@Param("params") Map<String, Object> params);

    @MapKey(value = "id")
    List<Map<Integer,String>> selectUserList(@Param("tenantId")Integer tenantId);

    @MapKey(value = "id")
    List<Map<Integer,String>> selectUserList();

    @Select("select connect_id from bdp_proc_connect where  proc_id = #{projectId}")
    List<Integer> queryIdsByProjectId(@Param("projectId") Integer projectId);

    @Select("select id from bdp_proc_info where name=#{name} limit 1")
    Integer selectByName(@Param("name")String name);
}
